import request from "@/utils/request";

// 客户列表
export function listCustomer(query, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/`,
    method: "get",
    params: query
  });
}
// 添加客户
export function QuickAddCustomer(data, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/`,
    method: "post",
    data
  });
}
// 编辑客户
export function editCustomer(data, category) {
  const id = data.customer;
  return request({
    url: `/crm/${category.toLowerCase()}/${id}/`,
    method: "patch",
    data
  });
}
// 删除客户
export function delCustomer(id, forced, category) {
  const is = forced ? 1 : 0;
  return request({
    url: `/crm/${category.toLowerCase()}/${id}/?forced=` + is,
    method: "delete"
  });
}
// 拉黑客户
export function blockCustomer(id, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/${id}/blacklist/`,
    method: "post"
  });
}
// 地区
export function getAreaList() {
  return request({
    url: "/crm/common/area_list/",
    method: "get"
  });
}
// 获取意向客户状态
export function customerStatus(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_ic_customer_status/?status=1",
    method: "get",
    params: query
  });
}
// 获取签约客户状态
export function customerScStatus(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_sc_customer_status/?status=1",
    method: "get",
    params: query
  });
}
// 查询系统信息
export function getUserDetail(id, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/${id}/`,
    method: "get"
  });
}
// 修改系统信息
export function updateUserDetail(id, data, method, category) {
  // const tmp_data = data;
  // if (data.is_focused) {
  //   tmp_data.is_focused = data.is_focused === "true";
  // }
  // console.log("data", data);

  return request({
    url: `/crm/${category.toLowerCase()}/${id}/`,
    method: method,
    data: data
  });
}
// 获取基本信息
export function getBaseDetail(id) {
  return request({
    url: `/crm/profile/?customer=` + id,
    method: "get"
  });
}
// 修改基本信息
export function updateBaseDetail(id, data) {
  var method = "";
  var url = "";
  if (id) {
    method = "put";
    url = `/crm/profile/${id}/`;
  } else {
    method = "post";
    url = "/crm/profile/";
  }
  return request({
    url: url,
    method: method,
    data: data
  });
}
// 查询单位信息
export function getWorkDetail(id) {
  return request({
    url: `/crm/enterprise/?customer=` + id,
    method: "get"
  });
}
// 修改单位信息
export function updateWorkrDetail(id, data) {
  var method = "";
  var url = "";
  if (id) {
    method = "put";
    url = `/crm/enterprise/${id}/`;
  } else {
    method = "post";
    url = "/crm/enterprise/";
  }
  return request({
    url: url,
    method: method,
    data: data
  });
}
// 获取行业
export function getIndustryList(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_industry/?status=1",
    method: "get",
    params: query
  });
}
// 发薪方式
export function getPayList(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_pay_method/?status=1",
    method: "get",
    params: query
  });
}
// 获取职业
export function getProfessionList(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_profession_category/?status=1",
    method: "get",
    params: query
  });
}
// 获取银行
export function getBankList(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_loan_bank/?status=1",
    method: "get",
    params: query
  });
}
// 附件类型
export function gettAttachmentList(query) {
  return request({
    url: "/admin/system/dict/get/type/crm_attachment_category/?status=1",
    method: "get",
    params: query
  });
}
// 查询房产
export function getAssetDetail(id) {
  return request({
    url: "/crm/asset_house/?customer=" + id,
    method: "get"
  });
}
// 修改房产
export function editAssetDetail(data) {
  const id = data.id;
  return request({
    url: `/crm/asset_house/${id}/`,
    method: "put",
    data: data
  });
}
// 删除房产
export function delAssetDetail(id) {
  return request({
    url: `/crm/asset_house/${id}/`,
    method: "delete"
  });
}
// 新增房产
export function addAssetDetail(data) {
  return request({
    url: "/crm/asset_house/",
    method: "post",
    data: data
  });
}
// 查询汽车
export function getAutoDetail(id) {
  return request({
    url: "/crm/asset_auto/?customer=" + id,
    method: "get"
  });
}
// 修改汽车
export function editAutoDetail(data) {
  const id = data.id;
  return request({
    url: `/crm/asset_auto/${id}/`,
    method: "put",
    data: data
  });
}
// 删除汽车
export function delAutoDetail(id) {
  return request({
    url: `/crm/asset_auto/${id}/`,
    method: "delete"
  });
}
// 添加汽车
export function addAutoDetail(data) {
  return request({
    url: "/crm/asset_auto/",
    method: "post",
    data: data
  });
}
// 查询信用
export function getCreditDetail(id) {
  return request({
    url: "/crm/credit/?customer=" + id,
    method: "get"
  });
}
// 修改信用
export function editCreditDetail(id, data) {
  var method = "";
  var url = "";
  if (id) {
    method = "put";
    url = `/crm/credit/${id}/`;
  } else {
    method = "post";
    url = "/crm/credit/";
  }
  return request({
    url: url,
    method: method,
    data: data
  });
}
// 获取日志
export function getLogList(type, query) {
  return request({
    url: `/crm/${type}/`,
    method: "get",
    params: query
  });
}
export function addFollowLog(data, category) {
  const customer = data.customer;
  delete data.customer;
  return request({
    url: `/crm/${category.toLowerCase()}/${customer}/add_follow_log/`,
    method: "post",
    data: data
  });
}
// 上传文件
export function uploadExcel1(data) {
  return request({
    url: `/crm/attachment/`,
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data
  });
}
// 上传文件
export function getUploadExcel(query) {
  return request({
    url: `/crm/attachment/`,
    method: "get",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    params: query
  });
}
// 删除已文件
export function delUploadExcel(id) {
  return request({
    url: `/crm/attachment/${id}/`,
    method: "delete",
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}
// 分配归属人
export function transOwer(data, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/bulk_change_owner/`,
    method: "post",
    data: data
  });
}
// 移到公海
export function transSea(data, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/bulk_change_category/`,
    method: "post",
    data: data
  });
}
// 个人信息导出数据
export function exportMessage(customer_id) {
  return request({
    url: `/crm/customer/${customer_id}/export_report/`,
    method: "post",
    responseType: "arraybuffer"
  });
}
// 全部导出通知
export function exportAllMessage(query, category) {
  return request({
    url: `/crm/${category.toLowerCase()}/export/`,
    method: "get",
    params: query
  });
}
// 下载用户导入模板
export function importTemplate() {
  return request({
    url: "/crm/customer/import/",
    method: "get",
    timeout: 300000
  });
}

// 用户导入
export function importsUser() {
  return request({
    url: "/admin/system/savefile/",
    method: "get"
  });
}
export function saveImportsUser(data) {
  return request({
    url: "/crm/cc/import_customer/ ",
    method: "post",
    data: data
  });
}
// 打电话
export function handleCall(id) {
  return request({
    url: `/crm/customer/${id}/call/`,
    method: "post"
  });
}
// 线索名称
export function getClueList() {
  return request({
    url: "/crm/clue/",
    method: "get"
  });
}
// // 查询用户详细
// export function getUser(userId) {
//   return request({
//     url: "/admin/permission/user/details/?userId=" + praseStrEmpty(userId),
//     method: "get"
//   });
// }

// // 新增用户
// export function addUser(data) {
//   return request({
//     url: "/admin/permission/user/",
//     method: "post",
//     data: data
//   });
// }

// // 修改用户
// export function updateUser(data) {
//   return request({
//     url: "/admin/permission/user/" + data.id + "/",
//     method: "put",
//     data: data
//   });
// }

// // 删除用户
// export function delUser(userId) {
//   return request({
//     url: "/admin/permission/user/" + userId + "/",
//     method: "delete"
//   });
// }

// // 查询用户个人信息
// export function getUserProfile() {
//   return request({
//     url: "/admin/permission/user/profile/",
//     method: "get"
//   });
// }

// // 修改用户个人信息
// export function updateUserProfile(data) {
//   return request({
//     url: "/admin/permission/user/profile/",
//     method: "put",
//     data: data
//   });
// }

// // 用户密码重置
// export function updateUserPwd(oldPassword, newPassword) {
//   const data = {
//     oldPassword,
//     newPassword
//   };
//   return request({
//     url: "/admin/permission/user/profile/updatePwd/",
//     method: "put",
//     data: data
//   });
// }

// // 用户头像上传
// export function uploadAvatar(data) {
//   return request({
//     url: "/admin/permission/user/profile/avatar/",
//     method: "put",
//     data: data
//   });
// }

// // 下载用户导入模板
// export function importTemplate() {
//   return request({
//     url: "/admin/permission/user/importTemplate/",
//     method: "get"
//   });
// }

// // 用户导入
// export function importsUser(data) {
//   return request({
//     url: "/admin/permission/user/importTemplate/",
//     method: "post",
//     data: data
//   });
// }

// // 获取线索名称
export function clueList(params) {
  return request({
    url: "/crm/clue/",
    method: "get",
    params
  });
}
// 自动分配线索
export function ccAutoDistribution(data) {
  return request({
    url: "/crm/cc/auto_distri/",
    method: "post",
    data
  });
}

